package me.jessyan.mvparms.demo.mvp.ui.adapter;

import android.view.View;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.jess.arms.base.BaseHolder;
import com.jess.arms.base.DefaultAdapter;
import com.platform.ai.control.R;

import java.util.List;

import butterknife.BindView;

import me.jessyan.mvparms.demo.mvp.model.entity.Social;

/**
 * Created by 95 on 2017/9/5.
 */
public class SocialAdapter extends DefaultAdapter<Social> {

    public SocialAdapter(List<Social> socials) {
        super(socials);
    }

    @Override
    public BaseHolder getHolder(View v, int viewType) {
        return new  SocialHolder(v);
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_social;
    }

    public class SocialHolder extends BaseHolder<Social> {
        @BindView(R.id.iv_sex)
        ImageView mSex;

        @BindView(R.id.tv_name)
        TextView mName;

        @BindView(R.id.tv_time)
        TextView mTime;

        @BindView(R.id.btn_author)
        Button mAuthor;

        @BindView(R.id.tv_content)
        TextView mContent;

        @BindView(R.id.iv_content)
        ImageView mImg;

        @BindView(R.id.tv_like)
        TextView mLike;

        @BindView(R.id.tv_reply)
        TextView mReply;

        @BindView(R.id.tv_download)
        TextView mDownload;

        public SocialHolder(View itemView) {
            super(itemView);
        }

        @Override
        public void setData(Social data, int position) {
            switch(data.getSex()){
                case 0:
                    mSex.setImageResource(R.drawable.icon_man);
                    break;
                case 1:
                    mSex.setImageResource(R.drawable.icon_woman);
                    break;
            }
            mName.setText(data.getUser_name());
            mTime.setText(data.getPublish_time());
            mContent.setText(data.getContent());
            mLike.setText(String.valueOf(data.getLike()));
            mReply.setText(String.valueOf(data.getReply()));
            mDownload.setText(String.valueOf(data.getDownload()));
            mAuthor.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Toast.makeText(itemView.getContext(),"授权成功,可以下载资源",Toast.LENGTH_SHORT).show();
                }
            });
        }
    }



}
